# Code to get monitor info
import numpy as np
import matplotlib.pyplot as plt
import sys
from PyQt5 import QtCore, QtWidgets

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure


# Test Git merge
def func_1():
    pass


def func_2():
    pass


def clamp(num_list):
    ret = []
    for item in num_list:
        if item < 0:
            item = 0
        elif item > 255:
            item = 255
        ret.append(round(item))
    return ret


# test matrix multiplication
mat1 = np.matrix([
    [1, 1, 1],
    [1, 1, 1],
    [1, 1, 1]
])

mat2 = np.matrix([2, 2, 2])

print(mat1 * mat2.T)

l = [1, 2, 3]
m = np.array([[1], [2], [3]])
q = m[:, 0]
# q = [item[0] for item in m]
# for item in m:
#     q.append(item[0])
# x, y, z = clamp(m)
print(q)
'''

# Test matplotlib  这里是如何将matplotlib画出来的曲线在Qt的窗口中显示
class MplCanvas(FigureCanvasQTAgg):

    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)
        super(MplCanvas, self).__init__(fig)


class MainWindow(QtWidgets.QMainWindow):

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        # Create the maptlotlib FigureCanvas object,
        # which defines a single set of axes as self.axes.
        sc = MplCanvas(self, width=5, height=4, dpi=100)
        sc.axes.plot([0, 1, 2, 3, 4], [10, 1, 20, 3, 40])
        self.setCentralWidget(sc)

        self.show()


app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
app.exec_()
'''

# Test polyfit
points = np.array([[1, 2], [4, 9], [2, 12], [0, 10]])  # 点集
x = np.array(points[:, 0])  # 点集的x坐标集合
y = np.array(points[:, 1])  # 点集的y坐标集合
z = np.polyfit(x, y, len(points) - 1)  # 返回多项式 [a, b, c]
p = np.poly1d(z)  # TODO: 返回函数p(x) = 3x^2 + 2x + 1给image_window
xp = np.linspace(-2, 6, 100)  # 返回从-2到6，间隔为1/100的点集
_ = plt.plot(x, y, '.', xp, p(xp))
plt.show()
